package com.maicss.coursedesign.fliter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class CheckLogin extends HttpFilter {
    @Override
    protected void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain) throws IOException, ServletException {
        String user = (String) req.getSession().getAttribute("user");
        if (user!=null){
            if (user.equals("")){
                res.sendError(505,"登录失效，请重新登录");
            }else {
                chain.doFilter(req,res);
            }
        }else {
            res.sendError(505,"登录失效，请重新登录");
        }
    }
}
